﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace DBShell
{
    class DataImporter
    {
        private string file;
        private string table;
        private string columnList;
        public DataImporter(string filename, string tablename)
        {
            file = filename;
            table = tablename;
        }

        public void ExecImport()
        {
            StreamReader sr = new StreamReader(file, System.Text.Encoding.Default);
            Console.Write(sr.CurrentEncoding.EncodingName);
            columnList = sr.ReadLine().Trim();
            columnList = "(" + columnList.Replace("\"","") + ")";
            string values;
            string cmd;
            while (!sr.EndOfStream)
            {
                values = sr.ReadLine().Trim();
                values = values.Replace('"', '\'');
                values = Util.ReplaceSpace(values);
                values = "(" + values + ")";
                cmd = "INSERT INTO " + table + " VALUES " + values;
                StringBuilder sb = new StringBuilder(cmd);
                StringBuilder result = new StringBuilder();
                Program.parseExe(sb, ref result);
            }
            sr.Close();

        }
    }
}
